<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Hos extends Base
{
    //卫生院列表
    public function index()
    {
        $res = Db::name('hospital')->select();
        $this->assign("res",$res);
        // dump($res);
        // exit;
        return $this->fetch();
    }
    //处理添加医院
    public function addhos()
    {
        $request = Request::instance();
        $post = $request->post();
        $data = [
            'hospital_name' =>$_POST['hospital_name'],
            'hospital_site' =>$_POST['hospital_site'],
            'hospital_status' =>0,
        ];
        // dump($data);
        // exit;
        $res = Db::name('hospital')->insert($data);
        if($res)
        {
            return $this->success('添加成功','hos/index');
        }
        else{
            return  $this->error('失败，请重新填写信息');
        }
    }
    //处理删除卫生院
    public function del($hospital_id)
    {
        $res = Db::name('hospital')->where('hospital_id',$hospital_id)->delete();
        if($res)
        {
            return $this->success('删除成功','hos/index');
        }
        else{
            return  $this->error('失败，请重新填写信息');
        }
    }

    //显示添加管理员页
    public function addhosadmin($hospital_id)
    {
        $data['hospital_id'] = $hospital_id;
        $this->assign('data',$data);
        return $this->fetch();
    }
     //处理添加医院管理员
     public function addhosadmin1()
     {
         $hos_pw ='123456';
         $request = Request::instance();
         $post = $request->post();
         $data = [
             'hos_phone' =>$_POST['hos_phone'],
             'hos_name' =>$_POST['hos_name'],
             'hospital_id' =>$_POST['hospital_id'],
             'hos_pw' =>md5($hos_pw),
         ];
        //  dump($data);
        //  exit;
         $res = Db::name('hos')->insert($data);
         if($res)
         {
             return $this->success('添加成功','hos/index');
         }
         else{
             return  $this->error('失败，请重新填写信息');
         }
     }
     //卫生院列表
    public function hoslist($hospital_id)
    {
        $res = Db::name('hos')->where('hospital_id',$hospital_id)->select();
        $this->assign("res",$res);
        // dump($res);
        // exit;
        return $this->fetch();
    }
     //处理删除医院管理员
     public function delhos($hos_id)
     {
         $res = Db::name('hos')->where('hos_id',$hos_id)->delete();
         if($res)
         {
             return $this->success('删除成功','hos/index');
         }
         else{
             return  $this->error('失败，请重新填写信息');
         }
     }
}